using NodeCanvas.Framework;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.AI;
using Yoozoo.Gameplay.Liberty.AI.Node;

namespace com.yoozoo.gta.Gameplay.Liberty.AI.Node.Npc.Condition
{
    public class NpcMoveToRevengePos : AIBaseNode
    {
        private float _visionDistance;
        private Vector3 _targetDestination;

        protected override void OnExecute()
        {
            var chaseTarget= _entity.battleAgent.GetTarget(TargetType.ChaseRevengeTarget);
            if (chaseTarget== null)
            {
                EndAction(false);
                return;
            }
            _visionDistance = _entity.propertyDataConfig.vision;
            var revengeTarget = chaseTarget;
            _targetDestination = revengeTarget.viewer.viewerRoot.position;
            SetDestination(_targetDestination);
        }

        protected override void OnUpdate()
        {
            if (Vector3.Distance(_targetDestination, _entity.viewer.viewerRoot.position) <=
                _visionDistance + 2f)
            {
                EndAction(true);
            }
        }

        // protected override void OnStop()
        // {
        //     base.OnStop();
        //     if (targetEntity.value != null)
        //     {
        //         targetEntity.value = null;
        //     }
        // }
    }
}